/**
 * 初始化题目详情对话框
 */
var SubjectsInfoDlg = {
	ztreeInstance : null,
	subjectsInfoData : {}
};

/**
 * 清除数据
 */
SubjectsInfoDlg.clearData = function() {
	this.subjectsInfoData = {};
}

/**
 * 设置对话框中的数据
 * 
 * @param key
 *            数据的名称
 * @param val
 *            数据的具体值
 */
SubjectsInfoDlg.set = function(key, val) {
	this.subjectsInfoData[key] = (typeof val == "undefined") ? $("#" + key)
			.val() : val;
	return this;
}

/**
 * 设置对话框中的数据
 * 
 * @param key
 *            数据的名称
 * @param val
 *            数据的具体值
 */
SubjectsInfoDlg.get = function(key) {
	return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
SubjectsInfoDlg.close = function() {
	parent.layer.close(window.parent.Subjects.layerIndex);
}

/**
 * 收集数据
 */
SubjectsInfoDlg.collectData = function() {
	this.set('answer').set('id').set('examClass').set('content').set('remark').set('helps').set('catagoryId').set('sort');
}

/**
 * 验证两个密码是否一致
 */
SubjectsInfoDlg.validateCaNo = function() {
	if(this.get('examClass') && this.get('content') && this.get('catagoryId')&& this.get('sort') ){  	
    	return true;
    } else {
    	return false;
    }
};

/**
 * 提交添加
 */
SubjectsInfoDlg.addSubmit = function() {
	this.clearData();
	this.collectData();


	// 提交信息
	var ajax = new $ax(Feng.ctxPath + "/subjects/add", function(data) {
		Feng.success("添加成功!");
		//window.parent.Subjects.table.refresh(window.parent.Subjects.queryString);
		SubjectsInfoDlg.close();
	}, function(data) {
		Feng.error("添加失败!" + data.responseJSON.message + "!");
	});
	ajax.set(this.subjectsInfoData);
	ajax.start();
}



/**
 * 提交修改
 */
SubjectsInfoDlg.editSubmit = function() {

	this.clearData();
	this.collectData();
	
//	if (!this.validateCaNo()) {
//		return;
//	}
	// 提交信息
	var ajax = new $ax(Feng.ctxPath + "/subjects/update", function(data) {
		Feng.success("修改成功!");
		window.parent.Subjects.table.refresh(window.parent.Subjects.queryString);
		SubjectsInfoDlg.close();
	}, function(data) {
		Feng.error("修改失败!" + data.responseJSON.message + "!");
	});
	ajax.set(this.subjectsInfoData);
	ajax.start();
}



/**
 * 修改题目答案选项
 */
SubjectsInfoDlg.optionSubmit = function() {

	this.clearData();
	this.collectData();
	this.set('a').set('b').set('c').set('d').set('e').set('f').set('g');
	
	var optionA = this.get("a");
	if(optionA == undefined || optionA == null||optionA == ''){
		Feng.error("请输入选项A的内容");
		$("#a").focus();
		return;
	}
	
	var optionB = this.get("b");
	if(optionB == undefined || optionB == null||optionB == ''){
		Feng.error("请输入选项B的内容");
		$("#b").focus();
		return;
	}
 
	// 提交信息
	var ajax = new $ax(Feng.ctxPath + "/subjects/optionAdd", function(data) {
		Feng.success("修改答案选项成功!");
		window.parent.Subjects.table.refresh(window.parent.Subjects.queryString);
		SubjectsInfoDlg.close();
	}, function(data) {
		Feng.error("修改答案选项失败!" + data.responseJSON.message + "!");
	});
	ajax.set(this.subjectsInfoData);
	console.log(this.subjectsInfoData);
	ajax.start();
}

/**
 * 点击父级编号input框时
 */
SubjectsInfoDlg.onClickDept = function(e, treeId, treeNode) {
	$("#caName").attr("value", SubjectsInfoDlg.ztreeInstance.getSelectedVal());
	$("#caNo").attr("value", treeNode.id);
};

/**
 * 显示父级菜单选择的树
 */
SubjectsInfoDlg.showMenuSelectTree = function() {
	Feng.showInputTree("caName", "pcodeTreeDiv", 15, 34);
};

$(function() {
	$("#examClass").val($("#examClassValues").val());
	$("#catagoryId").val($("#catagoryIdValues").val());
});
